package com.woniuxy.controller;

import com.woniuxy.dto.MyDto;
import com.woniuxy.node.TreeNode;
import com.woniuxy.pojo.User;
import com.woniuxy.service.WebService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class indexController {
    @Autowired
    private WebService webService;
    @RequestMapping("/index.do")
    public String zz(){
        return "index";
    }

    /**
     * 车位信息网页
     * @return
     */
    @RequestMapping("/carparking.do")
    public String carparking(){
        return "carparking/carparking";
    }
    /**
     * 车位信息详细网页
     */
    @RequestMapping("/toeditCarpage.do")
    public String carparking1(){ return "carparking/carparkingz";}
    /**
     * 订单页面
     */
    public String merchantorder(){
        return "order/merchantorder";
    }

    /**
     * 忘记密码
     * @return
     */
    @RequestMapping("/forget.do")
    public String forget(){
        System.out.println("zzz");
        return "user/forget";
    }

    /**
     * 注册账户
     * @return
     */
    @RequestMapping("/noway.do")
    public String noway(){
        return "user/noway";
    }

    /**
     * 商家认证
     * @return
     */
    @RequestMapping("/register.do")
    public String register(){
        return "user/register";
    }
    /**
     * 预约订单
     */
    @RequestMapping("/orderinformation.do")
    public String order(){
        return "order/merchantorder";
    }
    /**
     * 预约订单详情
     */
    @RequestMapping("/tomerchantorderz.do")
    public String tomerchantorderz(){
        return "order/merchantorderz";
    }
    /**
     *
     * 超时订单
     */
    @RequestMapping("/orderinformation1.do")
    public String order1(){
        return "order/order2";
    }
    /**
     * 超时详情
     */
    @RequestMapping("/toordr2z.do")
    public String order2(){
        return "order/order2z";
    }

    /**
     * 商家提成页面
     * @return
     */
    @RequestMapping("/merchatCommission.do")
    public String merchatCommission(){
        return "commission/commission";
    }
    /**
     *
     */
    @RequestMapping("/merchatCommission2.do")
    public String merchatCommission2(){
        return "commission/commission2";
    }
    /**
     * 提成详情页面
     * @return
     */
    @RequestMapping("/merchatCommission1.do")
    public String merchatCommission1(){
        return "commission/commission1";
    }

    /**
     * 评论页面
     * @return
     */
    @RequestMapping("/comment.do")
    public String comment(){
        return "comment/comment";
    }

    /**
     * 回复评论
     * @return
     */
    @RequestMapping("/returncomment.do")
    public String commentz(){
        return "comment/commentz";
    }
    /**
     * 添加车位
     */
    @RequestMapping("/toaddcarparking.do")
    public String toaddcarparking(){
        return "carparking/addcarparking";
    }
    /**
     * 进图地图页面
     */
    @RequestMapping("/map.do")
    public String map(){
        return "user/map";
    }
    /**
     *
     * 首页左侧框
     */
     @GetMapping("/loadIndexLeftMenu.do")
     @ResponseBody
    public  List<TreeNode> loadIndexLeftMenu(HttpServletRequest request){
         Subject subject = SecurityUtils.getSubject();
         Session session = subject.getSession();
         User user = (User) session.getAttribute("USER_SESSION");
         List<TreeNode> x  =webService.selectpermissionBypid(user.getId());
         System.out.println(x);
         return x   ;
     }
     @GetMapping("/indexlist.do")
    @ResponseBody
    public MyDto indexlist(){
         MyDto m=new MyDto();
         Subject subject = SecurityUtils.getSubject();
         Session session = subject.getSession();
         User user = (User) session.getAttribute("USER_SESSION");
         List<MyDto> res=webService.indexlist(user.getId());
         m.setData(res);
         m.setCode(200);
         return m;
     }
}
